/*    file: CMediaPort.h
 *    desc:
 *   
 * created: 2015-11-09
 *  author: chuanjiang.zh@qq.com
 * company: 
 */ 


#if !defined CMEDIAPORT_H_
#define CMEDIAPORT_H_

#include "MediaPort.h"
#include "Process.h"
#include "Sdp.h"
////////////////////////////////////////////////////////////////////////////

namespace detail
{
class RtpMedium
{
public:

    int localPort;
    std::string ip;
    int port;
    int payload;
    int mode;

    RtpMedium():
        localPort(),
        ip(),
        port(),
        payload(),
        mode()
    {
    }

    bool empty() const
    {
        return (payload == 0);
    }

};

}

class CMediaPort : public MediaPort
{
public:
    CMediaPort();
    ~CMediaPort();

	virtual void setOriginSdp(const std::string& sdp);

    virtual std::string getLocalSdp();

    virtual int setPeerSdp(std::string& peerSdp);

    virtual std::string getPeerSdp(std::string& offerSdp);

    virtual int start();

    virtual void stop();
    

    void setPath(const std::string& playerPath, const std::string& rtpPath,
        const std::string& vRtp, const std::string& aRtp);

protected:
    std::string apply(const std::string& localSdp, const std::string& peerSdp);

    int setup(const std::string& localSdp, const std::string& peerSdp);

    bool setupMedium(sdp::SessionDescription& local, sdp::SessionDescription& peer,
        const char* name, detail::RtpMedium& rtpMedium);

protected:
    std::string m_originSdp;

    std::string m_localSdp;
    std::string m_peerSdp;
    bool    m_connected;

    Process m_player;
    std::string m_playerPath;

    std::string m_rtpPlayPath;
    std::string m_vRtpPath; /// video rtp file
    std::string m_aRtpPath; /// audio rtp file
    Process m_vRtpProc;
    Process m_aRtpProc;

	detail::RtpMedium m_vMedium;
	detail::RtpMedium m_aMedium;

    bool m_running;

};
////////////////////////////////////////////////////////////////////////////
#endif //CMEDIAPORT_H_

